package com.weds.edwx.web;

import com.weds.core.annotation.Logs;
import com.weds.core.base.BaseCommPager;
import com.weds.core.base.BaseController;
import com.weds.core.base.BasePageSearch;
import com.weds.core.resp.JsonResult;
import com.weds.core.utils.DateUtils;
import com.weds.core.utils.StringUtils;
import com.weds.core.utils.coder.RSACoder;
import com.weds.dingtalk.constant.DingTalkParams;
import com.weds.dingtalk.service.PayDtService;
import com.weds.edpf.core.constant.WeiXinParams;
import com.weds.edwx.entity.*;
import com.weds.edwx.service.AccountService;
import com.weds.edwx.service.HairCutService;
import com.weds.edwx.util.WXPayConstants;
import com.weds.edwx.util.WXPayUtil;
import com.weds.pay.constants.PayParams;
import com.weds.pay.constants.PayType;
import com.weds.pay.lcsw.constants.LcswConstants;
import com.weds.pay.lcsw.entity.*;
import com.weds.pay.lcsw.service.LcswService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.*;

/**
 * @Author sjm
 * @Description 理发管理
 * @Date 2020-02-24
 */
@RestController
@RequestMapping(value = "/haircut")
@Api(value = "理发管理", description = "理发管理")
public class HairCutController extends BaseController {
    @Autowired
    private HairCutService hairCutService;

    private Logger log = LogManager.getLogger();

    @Logs
    @ApiOperation(value = "剩余次数", notes = "剩余次数")
    @RequestMapping(value = "/getResidualCounts", method = RequestMethod.POST)
    public JsonResult<ResidualCountEntity> getResidualCounts(@RequestBody HairCutReq hairCutReq) {

        Integer currentMonthcount= hairCutService.currentMonthResidualCounts(hairCutReq.getUserSerial());
        Integer totalMonthcount=hairCutService.totalResidualCounts(hairCutReq.getUserSerial());
        ResidualCountEntity rce=new ResidualCountEntity();
        rce.setRemainingMonth(currentMonthcount);
        rce.setRemainingTotal(totalMonthcount);

        return succMsgData(rce);
    }


    @Logs
    @ApiOperation(value = "预约记录(当天的消费记录)", notes = "预约记录(当天的消费记录)")
    @RequestMapping(value = "/selectAppointmentListByEntity", method = RequestMethod.POST)
    public JsonResult<BaseCommPager<AppointmentRecordEntity>> selectAppointmentListByEntity(@RequestBody BasePageSearch<HairCutReq> record) {
        setPageHelper(record);
        HairCutReq entity = record.getSearch();
        if (entity == null) {
            entity = new HairCutReq();
        }
        List<AppointmentRecordEntity> list = hairCutService.selectAppointmentListByEntity(entity.getUserSerial());
        return succMsgData(new BaseCommPager<AppointmentRecordEntity>(list));
    }


    @Logs
    @ApiOperation(value = "消费补贴次数(按月查询)", notes = "消费补贴次数(按月查询)")
    @RequestMapping(value = "/collectSum", method = RequestMethod.POST)
    public JsonResult<HairCutCollectSumEntity> collectSum(@RequestBody HairCutCollectReq hairCutCollectReq) {
        ///本月消费次数
        Integer currentMonthConsumecount= hairCutService.currentMonthConsumeCount(hairCutCollectReq);
        ///本月补贴次数
        Integer currentMonthSubsidycount=hairCutService.currentMonthSubsidyCount(hairCutCollectReq);

        HairCutCollectSumEntity hccse=new HairCutCollectSumEntity();
        hccse.setNewUsed(currentMonthConsumecount);///本月消费次数
        hccse.setNewSub(currentMonthSubsidycount);///本月补贴次数
        return succMsgData(hccse);
    }



    @Logs
    @ApiOperation(value = "消费记录补贴记录(按月查询)", notes = "消费记录补贴记录(按月查询)")
    @RequestMapping(value = "/selectHairCutConsumeSubsidyListByEntity", method = RequestMethod.POST)
    public JsonResult<BaseCommPager<HairCutConsumeSubsidyEntity>> selectHairCutConsumeSubsidyListByEntity(@RequestBody BasePageSearch<HairCutConsumeSubsidyReq> record) {
        setPageHelper(record);
        HairCutConsumeSubsidyReq entity = record.getSearch();
        if (entity == null) {
            entity = new HairCutConsumeSubsidyReq();
        }
        if(entity.getType()==0){
            //消费记录
            List<HairCutConsumeSubsidyEntity> list = hairCutService.selectHairCutListByEntity(entity);
            return succMsgData(new BaseCommPager<HairCutConsumeSubsidyEntity>(list));
        }else{
            //补贴记录
            List<HairCutConsumeSubsidyEntity> list = hairCutService.selectSubsidyListByEntity(entity);
            return succMsgData(new BaseCommPager<HairCutConsumeSubsidyEntity>(list));
        }
    }



/*
    @Logs
    @ApiOperation(value = "理发记录(按月查询)", notes = "理发记录(按月查询)")
    @RequestMapping(value = "/selectHairCutListByEntity", method = RequestMethod.POST)
    public JsonResult<List<HairCutRecordEntity>> selectHairCutListByEntity(@RequestBody HairCutListReq hairCutListReq) {
        List<HairCutRecordEntity> list = hairCutService.selectHairCutListByEntity(hairCutListReq);
        return succMsgData(list);
    }

*/
/*    @Logs
    @ApiOperation(value = "充值记录(按月查询)", notes = "充值记录(按月查询)")
    @RequestMapping(value = "/selectRechargeListByEntity", method = RequestMethod.POST)
    public JsonResult<List<RechargeRecordEntity>> selectRechargeListByEntity(@RequestParam Integer user_serial) {
        List<RechargeRecordEntity> list = hairCutService.selectRechargeListByEntity(user_serial);
        return succMsgData(list);
    }*//*


    @Logs
    @ApiOperation(value = "补贴记录(按月查询)", notes = "补贴记录(按月查询)")
    @RequestMapping(value = "/selectSubsidyListByEntity", method = RequestMethod.POST)
    public JsonResult<List<SubsidyRecordEntity>> selectSubsidyListByEntity(@RequestBody HairCutReq hairCutReq) {
        List<SubsidyRecordEntity> list = hairCutService.selectSubsidyListByEntity(hairCutReq.getUserSerial());
        return succMsgData(list);
    }
*/



}